package com.love.cloud.admin.notify.controller;


import com.love.cloud.admin.notify.entity.NotifyArticle;
import com.love.cloud.admin.notify.service.NotifyArticleService;
import com.love.cloud.admin.notify.vo.ArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/notify/article")
@Api(tags = "文章接口")
public class ArticleController {
    @Resource
    private NotifyArticleService notifyArticleService;

    @GetMapping(value = "/allArticlePage")
    public Object allArticlePage(ArticleVo articleVo){
        return notifyArticleService.allArticlePage(articleVo);
    }

    @GetMapping(value = "/articlePage")
    public Object articlePage(ArticleVo articleVo){
       return notifyArticleService.articlePage(articleVo);
    }

    @ApiOperation(value="删除文章")
    @DeleteMapping(value = "/deleteArticle/{articleId}")
    public Object deleteArticle(@PathVariable Long articleId){
        return this.notifyArticleService.removeById(articleId);
    }

    @ApiOperation(value="查看文章详情")
    @GetMapping(value = "/viewArticle/{articleId}")
    public Object viewArticle(@PathVariable Long articleId){
        return this.notifyArticleService.viewArticle(articleId);
    }

    @PostMapping(value = "/addArticle")
    public Object addArticle(@RequestBody NotifyArticle article){
        int result= notifyArticleService.saveArticle(article);
        return result;
    }

    @ApiOperation(value="发布文章")
    @PostMapping(value = "/pushArticle")
    public Object pushArticle(@RequestBody NotifyArticle article){
        return this.notifyArticleService.pushArticle(article);
    }

    @PostMapping(value = "/editArticle")
    public Object editArticle(@RequestBody NotifyArticle article){
        boolean result= notifyArticleService.updateById(article);
        return result;
    }
    /**
     * 用户点赞
     */
    @GetMapping(value = "/praiseArticle")
    public Object praiseArticle(Long articleId,Long userId) {
        Long result=notifyArticleService.praiseArticle(articleId,userId);
        return result;
    }
    /**
     * 用户取消点赞
     */
    @GetMapping(value = "/cancelPraiseArticle")
    public Object  cancelPraiseArticle(Long articleId,Long userId){
        Long result=notifyArticleService.cancelPraiseArticle(articleId,userId);
        return result;
    }
}
